package agents;

import jade.content.lang.sl.SLCodec;
import jade.core.Agent;
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.domain.mobility.MobilityOntology;
import jade.wrapper.ContainerController;
import jade.wrapper.StaleProxyException;

@SuppressWarnings("serial")
public class BootAgent extends Agent {

	// Get a JADE Runtime instance
	jade.core.Runtime runtime = jade.core.Runtime.instance();

	private ContainerController museumContainer = null;
	private ContainerController profilerContainer = null;
	private ContainerController tourGuideContainer = null;

	@Override
	protected void setup() {
		System.out.println(this.getLocalName() + ": Running setup()");

		// Register language and ontology
		getContentManager().registerLanguage(new SLCodec());
		getContentManager().registerOntology(MobilityOntology.getInstance());
		
		// Create containers	
		ProfileImpl prof_museum = new ProfileImpl();
		prof_museum.setParameter(Profile.CONTAINER_NAME, "Museum-Container");
		museumContainer = runtime.createAgentContainer(prof_museum);
		
		ProfileImpl prof_profiler = new ProfileImpl();
		prof_profiler.setParameter(Profile.CONTAINER_NAME, "Profiler-Container");
		profilerContainer = runtime.createAgentContainer(prof_profiler);

		ProfileImpl prof_tourguide = new ProfileImpl();
		prof_tourguide.setParameter(Profile.CONTAINER_NAME, "TourGuide-Container");
		tourGuideContainer = runtime.createAgentContainer(prof_tourguide);
		
		// Create agents
		try {
			museumContainer.createNewAgent("Curator", CuratorAgent.class.getName(), null).start();
			museumContainer.createNewAgent("Inventory", InventoryAgent.class.getName(), null).start();
			profilerContainer.createNewAgent("Profiler", ProfilerAgent.class.getName(), null).start();
			tourGuideContainer.createNewAgent("TourGuide", TourGuideAgent.class.getName(), null).start();
		} catch (StaleProxyException e) {
			// Should not happen
			e.printStackTrace();
		}

	}
}
